Visualizing Surveys in R by Valtonen Teppo;
Author:Valtonen, Teppo;
Language: eng
Format: epub
Publisher: CRC Press LLC
Published: 2023-11-03T00:00:00+00:00
8.2.1âParse NA values in numeric variables
Since I have read the data as text, I can also use the parse_integer() and parse_numeric() functions described in Section 6.1 and 6.2, respectively:
df %>% select( LSATIS11R_A) %>% mutate( lifesat11 = parse_integer( LSATIS11R_A, na = c( '97', '98', '99' ) ) ) %>% head()
## # A tibble: 6 x 2 ## LSATIS11R_A lifesat11 ## <chr> <int> ## 1 8 8 ## 2 8 8 ## 3 9 9 ## 4 8 8 ## 5 8 8 ## 6 10 10
8.2.2âNA values in categorical variables
If I have categorical variables, probably the easiest way is to use the function factor() and define non-NA values with the levels argument:
df %>% select( PAIFRQ3M_A) %>% mutate( pain = factor( PAIFRQ3M_A, levels = c( 1, 2, 3, 4 ) ) ) %>% head()
## # A tibble: 6 x 2 ## PAIFRQ3M_A pain ## <chr> <fct> ## 1 2 2 ## 2 4 4 ## 3 2 2 ## 4 4 4 ## 5 8 <NA> ## 6 8 <NA>
Like I described in Section 6.3, I can also use the function parse_factor() but if I don't want to get warnings, I have to define both NA and non-NA values explicitly:
df %>% select( PAIFRQ3M_A) %>% mutate( pain = parse_factor( PAIFRQ3M_A, levels = c( '1', '2', '3', '4' ), na = c( '7', '8', '9' ) ) ) %>% head()
## # A tibble: 6 x 2 ## PAIFRQ3M_A pain ## <chr> <fct> ## 1 2 2 ## 2 4 4 ## 3 2 2 ## 4 4 4 ## 5 8 <NA> ## 6 8 <NA>
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Whiskies Galore by Ian Buxton(41525)
Introduction to Aircraft Design (Cambridge Aerospace Series) by John P. Fielding(32885)
Rewire Your Anxious Brain by Catherine M. Pittman(18282)
Craft Beer for the Homebrewer by Michael Agnew(17928)
Cat's cradle by Kurt Vonnegut(14756)
Sapiens: A Brief History of Humankind by Yuval Noah Harari(13983)
Leonardo da Vinci by Walter Isaacson(12788)
The Tidewater Tales by John Barth(12391)
Underground: A Human History of the Worlds Beneath Our Feet by Will Hunt(11832)
Thinking, Fast and Slow by Kahneman Daniel(11780)
The Radium Girls by Kate Moore(11616)
The Art of Thinking Clearly by Rolf Dobelli(9908)
A Journey Through Charms and Defence Against the Dark Arts (Harry Potter: A Journey Throughâ¦) by Pottermore Publishing(9136)
Mindhunter: Inside the FBI's Elite Serial Crime Unit by John E. Douglas & Mark Olshaker(8697)
Tools of Titans by Timothy Ferriss(7806)
Wonder by R. J. Palacio(7736)
Turbulence by E. J. Noyes(7694)
Change Your Questions, Change Your Life by Marilee Adams(7369)
Nudge - Improving Decisions about Health, Wealth, and Happiness by Thaler Sunstein(7238)
